//
//  TalkfunTableViewCell.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/2/16.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TalkfunTableViewCell: UITableViewCell {

    @objc public let fileName = UILabel() // 名称
    @objc public let progressView = UIProgressView() //进度条
    @objc public let controlBtn = TalkfunIncreaseButton()//下载按钮变化
    @objc public let progressLabel = UILabel() //32.4/150.81MB
    @objc public let totalDuration = UILabel() //播放时长
    @objc public let fileProgressLabel = UILabel() //进度比例
    @objc public let downloadBtnLabel = UILabel() //下载状态 (已暂停 下载中  播放)
    @objc public let nameLab = UILabel()
    @objc public var tf_width:CGFloat = 0.0
    @objc public var tf_height:CGFloat = 0.0
    @objc public let linelab = UILabel()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.fileName.textColor = UIColor(red: 66/255.0, green: 67/255.0, blue: 68/255.0, alpha: 1.0)
        self.fileName.font = UIFont.PingFang(size: 17)
        self.contentView.addSubview(self.fileName)
      
        self.totalDuration.textColor = UIColor(red: 129/255.0, green: 133/255.0, blue: 136/255.0, alpha: 1.0)
        self.totalDuration.font = UIFont.PingFang(size: 14)
        self.contentView.addSubview(self.totalDuration)
        
        self.progressLabel.textColor = self.totalDuration.textColor
        self.progressLabel.font = self.totalDuration.font
        self.progressLabel.textAlignment = .right;
        self.contentView.addSubview(self.progressLabel)
        
        
        self.progressView.trackTintColor = UIColor(red: 220/255.0, green: 227/255.0, blue: 233/255.0, alpha: 1.0)
        
        self.progressView.progressTintColor = UIColor(red: 23/255.0, green: 145/255.0, blue: 251/255.0, alpha: 1.0)
        self.contentView.addSubview(self.progressView)
        
        //下载中  已暂停

        self.downloadBtnLabel.textColor = self.totalDuration.textColor
        self.downloadBtnLabel.font = self.totalDuration.font
        self.downloadBtnLabel.textAlignment = .right;
        self.contentView.addSubview(self.downloadBtnLabel)
        

        self.controlBtn.setImage(UIImage.init(named: "HTLive.bundle/beDownloading"), for: UIControl.State.normal)
        self.controlBtn.setImage(UIImage.init(named: "HTLive.bundle/beDownloading"), for: UIControl.State.selected)
        self.contentView.addSubview(self.controlBtn)
        
   
        self.nameLab.textColor = self.fileName.textColor
        self.nameLab.font =  self.totalDuration.font
        self.contentView.addSubview(self.nameLab)
 
        
         self.linelab.backgroundColor = UIColor(red: 229/255.0, green: 229/255.0, blue: 229/255.0, alpha: 1.0)
        self.contentView.addSubview(self.linelab)
        
       
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        self.fileName.frame = CGRect(x: 15, y: 13, width: self.tf_width-30-150, height: 24)
        
        self.totalDuration.frame =  CGRect(x: 15, y: self.fileName.frame.maxY + 4, width: 130, height: 20)
        
        let progressViewY = self.totalDuration.frame.maxY + 3
        self.progressView.frame = CGRect(x: 15, y: progressViewY, width: self.tf_width - 95, height:2 )
        
        let nameLabY = self.progressView.frame.maxY + 3
        self.nameLab.frame = CGRect(x: 15, y: nameLabY, width:100, height:20)
        
       
        self.controlBtn.frame = CGRect(x: self.tf_width-47, y: (self.tf_height-30)/2.0, width:30, height:30)

        let progressLabelY = self.fileName.frame.maxY + 4
        self.progressLabel.frame = CGRect(x: 145, y: progressLabelY, width:self.tf_width-145-80, height:20)
       
        let downloadBtnLabelY = self.progressView.frame.maxY + 3
        self.downloadBtnLabel.frame = CGRect(x: self.tf_width-80-100, y: downloadBtnLabelY, width:100, height:20)
        
    
        let linelabY = self.tf_height-1
        self.linelab.frame = CGRect(x:0, y: linelabY, width:self.tf_width, height:1)
        
      
    }

}
